package com.emc.greenplum.pigsterix.compiler;

import java.util.ArrayList;
import java.util.List;

import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IDataSink;
import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IDataSource;
import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IDataSourcePropertiesProvider;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.FunctionalDependency;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.INodeDomain;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.IPartitioningProperty;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty;
import edu.uci.ics.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector;

public class PigDataSource implements IDataSource<String>, IDataSink {
	private final String file;

	private final Object[] types;

	private IDataSourcePropertiesProvider propProvider;

	public PigDataSource(String file, Object[] types) {
		this.file = file;
		this.types = types;
		final IPhysicalPropertiesVector vec = new StructuralPropertiesVector(
				new RandomPartitioningProperty(new INodeDomain() {
					@Override
					public boolean sameAs(INodeDomain domain) {
						return true;
					}

					@Override
					public Integer cardinality() {
						return 0;
					}
				}), new ArrayList<ILocalStructuralProperty>());
		propProvider = new IDataSourcePropertiesProvider() {
			@Override
			public IPhysicalPropertiesVector computePropertiesVector(
					List<LogicalVariable> scanVariables) {
				return vec;
			}
		};
	}

	@Override
	public String getId() {
		return file;
	}

	@Override
	public Object[] getSchemaTypes() {
		return types;
	}

	@Override
	public IDataSourcePropertiesProvider getPropertiesProvider() {
		return propProvider;
	}

	@Override
	public void computeFDs(List<LogicalVariable> scanVariables,
			List<FunctionalDependency> fdList) {
	}

	@Override
	public IPartitioningProperty getPartitioningProperty() {
		return new RandomPartitioningProperty(new INodeDomain() {
			@Override
			public boolean sameAs(INodeDomain domain) {
				return true;
			}

			@Override
			public Integer cardinality() {
				return 0;
			}
		});
	}
}
